<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getDate(join, isTime = true) {

            const dt = new Date();

            const y = dt.getFullYear();
            const m = String(dt.getMonth() + 1).padStart(2, "0");
            // 1. 数据 + ""
            const d = (dt.getDate() + "").padStart(2, "0");

            // 2. 数据.toString()
            const hh = dt.getHours().toString().padStart(2, "0");
            // 3. String(数据)
            const mm = String(dt.getMinutes()).padStart(2, "0");
            const ss = dt.getSeconds();


            const date = [y, m, d].join(join);
            const time = [hh, mm, ss].join(':');

            if (isTime) {
                return date + ' ' + time;
            }

            return date;

        }

        const result = getDate("-", true);
        console.log(result);


        // 2025-05-13

        // 2025/05/13
    </script>
</body>

</html>